/**
 * Created with JetBrains PhpStorm.
 * User: cgp
 * Date: 13-4-10
 * Time: 下午3:22
 */
Object.countObj = function(obj) {
    var size = 0,key;
    for(key in obj) {
        if(obj.hasOwnProperty(key)) size ++;
    }
    return size;
};
//var baseUrl = 'call/jh_prod_f.php',
 var baseUrl = 'call/pppp.php',
    pid = parseInt($("input[name='pid']").val()),
    lastid = parseInt($("input[name='lastid']").val()),
    did = parseInt($("input[name='did']").val());
var goBack = function() {
    history.go(-1);
};
jQuery(document).ready(function($){

    //保存营销活动信息
    $("button#saveProduct").bind('click',function(){ 
        var mainTitle = $("input[name='mainTitle']"),
            that = $(this),
            step = $(this).attr('data-step') || 1,
            landid = parseInt($("#mainForm").find("input[name='lastid']").val());
        if(mainTitle.val() == '' ) {
            alert('活动名称不能为空');
            mainTitle.focus();
            return;
        }
        //var postData = $("form#mainForm").serialize(),btnTxt = $(this).text();
		 $("#mainForm").submit();
		 // location.href="marketing_product.html";
		// $.ajax({
            // type:'POST', 
			// url: baseUrl,
			// data: postData, 
			// dataType:'json',
            // beforeSend:function(){
                // that.text('保存中...').attr('disabled','disabled');
            // },
            // timeout: 10000}).done(function(result){
				// if(result.status=='ok') {
                    // if(!landid) {
                        // location.href="marketing_product.html?sid="+result.lastid+"&step=2";
                    // } else {
                        // alert(result.msg);
                    // }
                // } else{
                    // alert(result.msg);
                // }
                // that.text(btnTxt).removeAttr('disabled');
            // })
               // .error(function(XMLHttpRequest, textStatus, errorThrown) {
                // that.text(btnTxt).removeAttr('disabled');
                // if(textStatus == 'timeout') {
                    // alert("请求已经超时,保存失败");
                // } else {
                    // alert("其他错误,保存失败。");
                // }
            // });
    });
    //图片上传
	$("#BtnUpload").bind('click',function(){
        if(!$("input#imgup").val().length) return;
        $("#upload_mth").val("0");
        $("form#mainForm").submit();
        $("#waitingUpload").html('<img src="images/loading.gif" alt="图片上传中"/>图片上传中..').show();
    });
});
